package com.dianning.service.imp;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import org.apache.commons.logging.*;

import com.dianning.bean.AdSpace;
import com.dianning.bean.Message;
import com.dianning.bean.Orders;
import com.dianning.bean.Visitor;
import com.dianning.dao.AdAdsDAO;
import com.dianning.dao.AdSpaceDAO;
import com.dianning.dao.MessageDAO;
import com.dianning.dao.OrdersDAO;
import com.dianning.dao.UserInfoDAO;
import com.dianning.dao.VisitorDAO;
import com.dianning.exception.DianningException;
import com.dianning.service.AdService;
import com.dianning.service.MessageService;
import com.dianning.service.OrdersService;
import com.dianning.service.VisitorService;
import com.dianning.service.web.PageList;
import com.dianning.service.web.Pages;

public class OrdersServiceImp implements OrdersService {

	private static final Log logger = LogFactory.getLog(OrdersServiceImp.class);

	private OrdersDAO ordersDAO;

	public OrdersDAO getOrdersDAO() {
		return ordersDAO;
	}

	public void setOrdersDAO(OrdersDAO ordersDAO) {
		this.ordersDAO = ordersDAO;
	}

	/**
	 * 保存Orders对象
	 * 
	 * @param orders
	 * 			Orders对象
	 * @return Orders
	 * 			Orders对象
	 */
	public Orders saveOrders(Orders orders){
		this.getOrdersDAO().saveOrders(orders);
		return orders;
	}
	
	/**
	 * 更新Orders对象
	 * 
	 * @param orders
	 * 			Orders对象
	 * @return Orders
	 * 			Orders对象
	 */
	public Orders updateOrders(Orders orders){
		return this.getOrdersDAO().updateOrders(orders);
	}
	
	public void updateOrdersIsnew(long uid,int isnew){
		this.getOrdersDAO().updateOrdersIsnew(uid, isnew);
	}
	
	/**
	 * 根据主键ID获取Orders对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Orders
	 * 			Orders对象
	 */
	public Orders findOrdersById(long id){
		return this.getOrdersDAO().findOrdersById(id);
	}
	
	/**
	 * 获取Message对象列表
	 * @param fromuid
	 * @param touid
	 * @param folder
	 * @param isnew
	 * @param delstatus
	 * @param orderby
	 * @param ascOrDesc
	 * @param pages
	 * @return PageList
	 */
	public PageList findOrders(long uid,int isnew,int delstatus,String orderby, int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getOrdersDAO().getOrdersNum(uid, isnew, delstatus));
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	return pl;
        }
		List l = this.getOrdersDAO().findOrders(uid, isnew, delstatus, orderby, ascOrDesc,pages.getSpage(), pages.getPerPageNum());
		pl.setObjectList(l);
	    pl.setPages(pages);
	    return pl;
	}
}
